###############################################################################
# SuperLinks                                                                  #
# Copyright (c) 2000-2007 Greg Nolle (http://greg.nolle.co.uk)                #
###############################################################################
# This program is free software; you can redistribute it and/or modify it     #
# under the terms of the GNU General Public License as published by the Free  #
# Software Foundation; either version 2 of the License, or (at your option)   #
# any later version.                                                          #
#                                                                             #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       #
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for   #
# more details.                                                               ##                                                                             #
# You should have received a copy of the GNU General Public License along     #
# with this program; if not, write to the Free Software Foundation, Inc.,     #
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.                 #
###############################################################################
# ControlPanel/Output/ApproveResources.pm.pl -> ApproveResources module       #
###############################################################################
# DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING!                         #
###############################################################################
package Skin::CP::ApproveResources;

BEGIN { require "System.pm.pl"; import System qw($SYSTEM); }
BEGIN { require "General.pm.pl"; import General qw($GENERAL); }
require "Standard.pm.pl";

use HTML::Dialog;
use strict;

sub new {
  my ($class) = @_;
  my $self    = {};
  return bless ($self, $class);
}

sub DESTROY { }

###############################################################################
# show subroutine
sub show {
  my $self = shift;
  my %in = (input => undef, @_);

  #----------------------------------------------------------------------#
  # Printing page...                                                     #

  my $Dialog = HTML::Dialog->new();

  my $Body;
  
  if (scalar(@{ $in{'input'}->{'FLAGGED_RESOURCES'} }) >= 1) {
    $Body = $Dialog->TableRow(items => [{ body => "Some of the resources you have selected have been flagged for deletion. Do you want to delete them now? (If you choose No then they will be unflagged)", colspan => 2 }]);
  
    $Body .= $Dialog->FormRadio(
      name    => "FORM_REMOVE",
      value   => "1",
      items   => [
        { value => "1", label => "Yes" },
        { value => "0", label => "No" }
      ], join => "<br>"
    );
  }
  
  $Body .= $Dialog->TableRow(items => [{ body => "Do you want email notices to be sent to each resource's contact email address?", colspan => 2 }]);
  
  $Body .= $Dialog->FormRadio(
    name    => "FORM_EMAIL",
    value   => "1",
    items   => [
      { value => "1", label => "Yes" },
      { value => "0", label => "No" }
    ], join => "<br>"
  );
  
  $Body .= $Dialog->FormButton(
    items => [
      { type => "submit", value => "Proceed" },
      { type => "reset", value => "Cancel" }
    ], join => "&nbsp;"
  );
  
  $Body = $Dialog->Table(body => $Body);
  $Body = $Dialog->StandardPage(
    body    => $Body,
    header  => "Approve Resources",
    form    => 1,
    hiddens => [
      { name => "Referer", value => $SL::QUERY{'Referer'} },
      { name => "RID", value => [$SL::CGI->param('RID')] },
      { name => "action", value => "DoApproveResources" },
      { name => "CP", value => "1" },
      { name => "SID", value => $SL::ADMIN{'SID'} }
    ]
  );

  return $Body;
}

###############################################################################
# do subroutine
sub do {
  my $self = shift;
  my %in = (input => undef, @_);

  #----------------------------------------------------------------------#
  # Printing page...                                                     #

  my $Dialog = HTML::Dialog->new();

  return $Dialog->StandardPage(
    body    => qq~The selected resources have been approved.<p>Click <a href="~.($SL::QUERY{'Referer'} || "$SYSTEM->{'SCRIPT_URL'}?CP=1&action=Resources&SID=$SL::ADMIN{'SID'}").qq~">here</a> if you're not redirected in 5 seconds.~,
    header  => "Approve Resources",
    metas   => [
      { http_equiv => "refresh", content => "5; url=".($SL::QUERY{'Referer'} || "$SYSTEM->{'SCRIPT_URL'}?CP=1&action=Resources&SID=$SL::ADMIN{'SID'}") }
    ]
  );
}

###############################################################################
# email subroutine
sub email {
  my $self = shift;
  my %in = (type => "", input => undef, @_);

  #----------------------------------------------------------------------#
  # Preparing data...                                                    #

  my %FIELDS;
  
  $FIELDS{'category'} = $in{'input'}->{'CATEGORY'};
  $FIELDS{'resource'} = $in{'input'}->{'RESOURCE'};

  $in{'input'}->{'RESOURCE'}->{'flags'} = &Standard::ArrayToHash([ split(/,/, $in{'input'}->{'RESOURCE'}->{'FLAGS'}) ]);
  $in{'input'}->{'RESOURCE'}->{'extra'} = eval($in{'input'}->{'RESOURCE'}->{'EXTRA'});
  $in{'input'}->{'CATEGORY'}->{'extra'} = eval($in{'input'}->{'CATEGORY'}->{'EXTRA'});

  #----------------------------------------------------------------------#
  # Printing email...                                                    #

  my $LANGUAGE = &Standard::GetLanguage("CPApproveResources");
  
  my %Return;

  $Return{'MESSAGE'} = &Standard::Substitute(
    INPUT     => "Emails/CPDoApproveResources-User.txt",
    STANDARD  => 1,
    FIELDS    => \%FIELDS
  );
  $Return{'MESSAGE'} = &Standard::Textize($Return{'MESSAGE'}) unless ($GENERAL->{'HTML_IN_USER_EMAILS'});
  $Return{'TO'} = $in{'input'}->{'RESOURCE'}->{'CONTACT_EMAIL'};
  $Return{'SUBJECT'} = &Standard::Substitute(
    INPUT     => \$LANGUAGE->{'EMAILSUBJECT-USER'},
    STANDARD  => 1,
    FIELDS    => \%FIELDS
  );
  $Return{'HTML'} = $GENERAL->{'HTML_IN_USER_EMAILS'};

  return %Return;
}

1;